home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / ubiquity / localechooser / localechooser < prev    next >
Text File  |  2009-10-28  |  20KB  |  725 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. . /usr/share/debconf/confmodule
  5.  
  6. db_capb backup
  7.  
  8. tpl_di_locale="debian-installer/locale"
  9. tpl_di_fallbacklocale="debian-installer/fallbacklocale"
  10. tpl_di_language="debian-installer/language"
  11. tpl_di_country="debian-installer/country"
  12. tpl_di_consoledisplay="debian-installer/consoledisplay"
  13. tpl_languagelist="localechooser/languagelist"
  14. tpl_shortlist="localechooser/shortlist"
  15. tpl_continentlist="localechooser/continentlist"
  16. tpl_countrylist="localechooser/countrylist"
  17. tpl_supportedlocales="localechooser/supported-locales"
  18.  
  19. SUPPORTEDLOCALES=/usr/lib/ubiquity/localechooser/SUPPORTED
  20. if [ ! -f "$SUPPORTEDLOCALES" ]; then
  21.     SUPPORTEDLOCALES=/usr/share/i18n/SUPPORTED
  22. fi
  23. SHORTLISTS=/etc/shortlists
  24. if [ ! -f "$SHORTLISTS" ]; then
  25.     SHORTLISTS=/usr/lib/ubiquity/localechooser/shortlists
  26. fi
  27. LANGUAGELISTFILE=/usr/lib/ubiquity/localechooser/languagelist
  28. LANGUAGELISTDATA=/usr/lib/ubiquity/localechooser/languagelist.data.gz
  29.  
  30. ORIG_IFS="$IFS"
  31. NL="
  32. "
  33.  
  34. error() {
  35.     logger -t localechooser "error: $@"
  36.     exit 1
  37. }
  38.  
  39. log() {
  40.     logger -t localechooser "info: $@"
  41. }
  42.  
  43.  
  44. locale2countrycode() {
  45.     if [ -n "$1" ]; then
  46.         if echo $1 | grep -q "_"; then
  47.             echo $1 | cut -f2 -d_ | cut -f1 -d@ | cut -f1 -d\.
  48.         else
  49.             echo
  50.         fi
  51.     else
  52.         error "Missing argument"
  53.     fi
  54. }
  55.  
  56. choices_add() {
  57.     echo "${1:+$1, }$2"
  58. }
  59.  
  60. # Determine the display level
  61. language_display_level() {
  62.     local level
  63.  
  64.     #log "Frontend in use: $DEBIAN_FRONTEND"
  65.     case $DEBIAN_FRONTEND in
  66.         gtk)
  67.         level=4 ;;
  68.         *)
  69.         # Keep only Latin1 languages if we don't have a framebuffer
  70.         if [ "$TERM_FRAMEBUFFER" ]; then
  71.             level=3
  72.         else
  73.             level=1
  74.         fi
  75.         # ASCII only if we are on serial console or a dumb terminal
  76.         # Both variables should already be set at init time
  77.         if [ "$TERM_TYPE" = "serial" ] || [ "$TERM" = "dumb" ]; then
  78.             level=0
  79.         fi
  80.         ;;
  81.     esac
  82.  
  83.     if [ "$OVERRIDE_SHOW_ALL_LANGUAGES" ]; then
  84.         level=4
  85.     fi
  86.     #log "Language display level is $level"
  87.     echo $level
  88. }
  89.  
  90. # Build list of available languages for a display level
  91. build_language_template() {
  92.     local level=$1
  93.     local oldlevel=$(cat /var/lib/localechooser/langlevel \
  94.         2>/dev/null || true)
  95.     if [ "$level" = "$oldlevel" ]; then
  96.         return 0
  97.     fi
  98.  
  99.     local IFS RET line name codes names_en names_both
  100.     rm -f /var/lib/localechooser/langlevel
  101.  
  102.     IFS="$NL"
  103.     for line in $(zcat $LANGUAGELISTDATA | grep "^[0-$level]:"); do
  104.         name="$(echo "$line" | cut -d: -f3)"
  105.         codes="$(choices_add "$codes" \
  106.             "$(echo "$line" | cut -d: -f2)")"
  107.         names_en="$(choices_add "$names_en" \
  108.             "$name")"
  109.         names_both="$(choices_add "$names_both" \
  110.             "$name\${!TAB}-\${!TAB}$(echo "$line" | cut -d: -f4)")"
  111.     done
  112.     IFS="$ORIG_IFS"
  113.  
  114.     db_subst $tpl_languagelist CODES "$codes"
  115.     db_subst $tpl_languagelist NAMES_EN "$names_en"
  116.     db_subst $tpl_languagelist NAMES_BOTH "$names_both"
  117.  
  118.     echo $level >/var/lib/localechooser/langlevel
  119. }
  120.  
  121.  
  122. do_preseed() {
  123.     local RET
  124.  
  125.     LOCALE="$1"
  126.     log "Locale has been preseeded to $LOCALE"
  127.  
  128.     # Only mark variables seen if this one was preseeded seen.
  129.     db_fget $tpl_di_locale seen
  130.     seenflag=$RET
  131.     db_fset $tpl_di_locale seen false || true
  132.  
  133.     # Only populate debconf if this is a supported locale
  134.     # and if the language is supported in D-I
  135.     LANGUAGE=${LOCALE%%.*}
  136.     if ! has_choice $tpl_languagelist "$LANGUAGE"; then
  137.         LANGUAGE=${LANGUAGE%%_*}
  138.         if ! has_choice $tpl_languagelist "$LANGUAGE"; then
  139.             LOCALE=""
  140.             LANGUAGE=""
  141.             log "Preseeded locale ignored: unsupported language"
  142.             return
  143.         fi
  144.     fi
  145.  
  146.     db_set $tpl_languagelist $LANGUAGE
  147.     log "Set $tpl_languagelist = '$LANGUAGE'"
  148.     db_fset $tpl_languagelist seen $seenflag || true
  149.     COUNTRY=$(locale2countrycode "$LOCALE")
  150.     if [ -n "$COUNTRY" ]; then
  151.         db_set $tpl_di_country "$COUNTRY"
  152.         log "Set $tpl_di_country = '$COUNTRY'"
  153.         db_fset $tpl_di_country seen $seenflag || true
  154.         db_fset $tpl_continentlist seen $seenflag || true
  155.         country_preseeded=1
  156.  
  157.         if grep -q "^$LOCALE " $SUPPORTEDLOCALES ; then
  158.             db_set $tpl_di_locale $LOCALE
  159.             db_fset $tpl_di_locale seen $seenflag || true
  160.             db_fset $tpl_supportedlocales seen $seenflag || true
  161.             log "Set $tpl_di_locale = '$LOCALE'"
  162.         else
  163.             # The locale was invalid, empty it
  164.             LOCALE=""
  165.         fi
  166.     fi
  167. }
  168.  
  169. # Install specific packages depending on selected language
  170. # Those we install here are those required immediately
  171. # Otherwise we will install them in finish-install
  172. install_lang_specific() {
  173.     if [ "$LOCALE" != "C" ]; then
  174.         case "$LANGUAGE" in
  175.             ar|el|fa|he|ja|ko|ku|tr|vi|wo|zh*)
  176.             # We need a complete font for later steps
  177.             anna-install bterm-unifont
  178.             ;;
  179.         esac
  180.     fi
  181. }
  182.  
  183. # Change language and switch font for graphical installer
  184. set_debconf_language() {
  185.     local RET
  186.  
  187.     db_set "debconf/language" "$1"
  188.  
  189.     if type gtk-set-font >/dev/null 2>&1; then
  190.         gtk-set-font || true
  191.     fi
  192. }
  193.  
  194. # Determine which template to display to warn for incomplete translations
  195. # and fill in the variable contents
  196. warning_template() {
  197.     local RET status template tbase twarn tabort
  198.     status=$1
  199.     tbase=localechooser/translation
  200.  
  201.     case $status in
  202.         0)    twarn=incomplete; tabort=abort ;;
  203.         1)    twarn=normal-ok; tabort=abort ;;
  204.         2)    twarn=partial; tabort=maybe-abort ;;
  205.         3)    twarn=mostly-ok ;;
  206.         4)    twarn=exceptions ;;
  207.     esac
  208.     if [ $status -le 2 ]; then
  209.         template=$tbase/warn-severe
  210.         db_metaget $tbase/text/$tabort description
  211.         db_subst $template TXT-ABORT "$RET"
  212.     else
  213.         template=$tbase/warn-light
  214.     fi
  215.  
  216.     # Languages that have fallbacks may have special templates
  217.     if [ "$twarn" != exceptions ] && \
  218.        expr $LANGUAGELIST : ".*:" >/dev/null && \
  219.        db_metaget $tbase/text/warn_$twarn/$LANGUAGE description; then
  220.         :
  221.     else
  222.         db_metaget $tbase/text/warn_$twarn description
  223.     fi
  224.     db_subst $template TXT-WARN "$RET"
  225.  
  226.     echo $template
  227. }
  228.  
  229. # Test if a template has the requested value among its choices
  230. has_choice() {
  231.     local RET template value
  232.     template="$1"
  233.     value="$2"
  234.  
  235.     [ "$value" ] || return 1
  236.  
  237.     db_metaget $template Choices-C
  238.     echo " $RET," | grep -q " $value,"
  239. }
  240.  
  241. # Set defaults for continent based on country
  242. set_default_continent() {
  243.     local IFS RET country continents c continent
  244.     country="$1"
  245.  
  246.     if [ -z "$country" ]; then
  247.         db_reset $tpl_continentlist
  248.         return
  249.     fi
  250.  
  251.     # Use Choices-en.UTF-8 to avoid getting translated values
  252.     db_metaget $tpl_continentlist Choices-en.UTF-8
  253.     continents=$(echo $RET | sed "s/, /,/g")
  254.  
  255.     IFS=,
  256.     for continent in $continents; do
  257.         IFS="$ORIG_IFS"
  258.         c=$(echo "$continent" | sed "s/ /_/g")
  259.         if has_choice $tpl_countrylist/$c "$country"; then
  260.             db_set $tpl_continentlist "$continent"
  261.             break
  262.         fi
  263.     done
  264. }
  265.  
  266. # Test if a locale includes a country part
  267. is_complete_locale() {
  268.     echo "$1" | grep -q "_"
  269. }
  270.  
  271. # Find the preferred locale given language, country, and encoding.
  272. preferred_locale() {
  273.     OLDIFS="$IFS"
  274.     IFS="$NL"
  275.     # Look for locales with the right encoding first.
  276.     for trylocale in $(grep "^$1_$2" $SUPPORTEDLOCALES || true); do
  277.         IFS="$OLDIFS"
  278.         if [ -z "$3" ] || [ "${trylocale#* }" = "$3" ]; then
  279.             echo "${trylocale% *}"
  280.             return
  281.         fi
  282.         IFS="$NL"
  283.     done
  284.     # Pick the first of any other available locales.
  285.     for trylocale in $(grep "^$1_$2" $SUPPORTEDLOCALES || true); do
  286.         IFS="$OLDIFS"
  287.         echo "${trylocale% *}"
  288.         return
  289.     done
  290.     IFS="$OLDIFS"
  291. }
  292.  
  293. # Find a supported locale which best fits the selected language and country.
  294. # Refinement: use the modifier inherited from language selection (if the
  295. # resulting locale is valid).
  296. get_default_locale() {
  297.     local lang fallback entry
  298.     lang=${LANGUAGE%%_*}
  299.  
  300.     # Special handling of cases where the locale defined in the
  301.     # language list is NOT the combination of language_COUNTRY.
  302.     # Used for Norwegian Bokmal transition in order to keep no_NO as
  303.     # locale. May be used in the future for other special cases, so
  304.     # we'd better keep this.
  305.     fallback=$(echo "$FALLBACKLOCALE" | sed -e 's/[.@].*$//')
  306.     if [ "$COUNTRYCODE" = "$DEFAULT_COUNTRY" ] && \
  307.        [ "${lang}_${COUNTRYCODE}" != "$fallback" ] && \
  308.        is_complete_locale "$fallback"; then
  309.         # Explanation: we fall back to the locale inherited from the
  310.         # language step if the country selection did NOT result in
  311.         # a change in country but the resulting locale is different
  312.         # from the one we had in first step.
  313.         return
  314.     fi
  315.  
  316.     # Check if a valid locale exists for the selected language + country
  317.     PREFERRED_LOCALE="$(preferred_locale "$lang" "$COUNTRYCODE" "$ENCODING")"
  318.     if [ "$PREFERRED_LOCALE" ]; then
  319.         echo "$PREFERRED_LOCALE"
  320.     fi
  321. }
  322.  
  323. # Extract a value from /etc/lsb-release
  324. lsb_extract () {
  325.     [ -f /etc/lsb-release ] || return 0
  326.     grep "^$1=" /etc/lsb-release | \
  327.         sed 's/^[^=]*=//; s/^"//; s/"$//' || true
  328. }
  329.  
  330.  
  331. # Reset all variables
  332. LANGUAGE=""
  333. COUNTRY=""
  334. LOCALE=""
  335.  
  336. # debconf/language is an alias for debian-installer/language
  337. db_register "$tpl_di_language" "debconf/language"
  338.  
  339. # Only display the translated texts (ie the English "translation") when in
  340. # UTF-8 mode. Note: seems the only case this triggers is serial console;
  341. # probably not needed anymore: we already limit which languages we display.
  342. if echo $LANG $LC_CTYPE | grep -q UTF-8; then
  343.     INITIAL_LANGUAGE=en
  344. else
  345.     INITIAL_LANGUAGE=""
  346. fi
  347.  
  348. db_fget $tpl_languagelist seen
  349. if [ "$RET" = true ]; then
  350.     db_get $tpl_languagelist
  351.     PREVIOUS_LANGUAGE="$RET"
  352. else
  353.     PREVIOUS_LANGUAGE=""
  354. fi
  355.  
  356. # Find the display level and set languages in the template
  357. # Needs to be done before checking preseeding, so we can preseed the
  358. # correct template.
  359. build_language_template $(language_display_level)
  360.  
  361. # Support preseeding of the locale all in one variable for convenience.
  362. # Only check for preseeding the first time localechooser is run.
  363. country_preseeded=""
  364. if [ ! -f /var/lib/localechooser/preseeded ]; then
  365.     if db_get $tpl_di_locale && [ "$RET" ]; then
  366.         do_preseed $RET
  367.     elif db_get $tpl_di_language && [ "$RET" ]; then
  368.         LANGUAGE="$RET"
  369.         db_fget $tpl_di_language seen
  370.         seenflag=$RET
  371.         LANGUAGE="${LANGUAGE%%.*}"
  372.         if ! grep -q "^$LANGUAGE;" $LANGUAGELISTFILE; then
  373.             LANGUAGE="${LANGUAGE%%_*}"
  374.             if ! grep -q "^$LANGUAGE;" $LANGUAGELISTFILE; then
  375.                 LANGUAGE="$(grep "^${LANGUAGE}_" $LANGUAGELISTFILE | \
  376.                     head -n1 | cut -d';' -f1)"
  377.             fi
  378.         fi
  379.         if [ -n "$LANGUAGE" ]; then
  380.             db_set $tpl_languagelist $LANGUAGE
  381.             log "Set $tpl_languagelist = '$LANGUAGE'"
  382.             db_fset $tpl_languagelist seen $seenflag || true
  383.         fi
  384.     fi
  385.  
  386.     >/var/lib/localechooser/preseeded
  387. fi
  388.  
  389.  
  390. # Main loop starts here
  391. # Use a state machine to allow jumping back to previous questions.
  392. # Main states are multiples of 10 to allow "preparation" states to be
  393. # skipped when backing up.
  394. STATE=10
  395. while :; do
  396.     case "$STATE" in
  397.        10)    # Display language list
  398.         sel_language=1
  399.         # Disabled because of #470258: template is set to true too early
  400.         if false && \
  401.            db_get debconf/translations-dropped && [ "$RET" = true ]; then
  402.             db_fget $tpl_languagelist seen
  403.             if [ "$RET" != true ]; then
  404.                 sel_language=""
  405.                 db_input high localechooser/translation/no-select || true
  406.             fi
  407.         else
  408.             # Set initial language for correct display of list
  409.             set_debconf_language $INITIAL_LANGUAGE
  410.  
  411.             db_capb backup align
  412.             db_input critical $tpl_languagelist || [ $? -eq 30 ]
  413.         fi
  414.         ;;
  415.  
  416.        11)    # We have a language
  417.         db_get $tpl_languagelist
  418.         LANGUAGE="$RET"
  419.  
  420.         if [ "$LANGUAGE" = "$PREVIOUS_LANGUAGE" ]; then
  421.             # The user picked the same language as before. We
  422.             # don't need to reset the default country and
  423.             # locale, and doing so may be confusing.
  424.             STATE=12
  425.             continue
  426.         fi
  427.  
  428.         # Determine defaults based on languagelist
  429.         . languagemap
  430.         db_set "$tpl_di_language" "$LANGUAGELIST"
  431.         log "Set $tpl_di_language = '$LANGUAGELIST'"
  432.         db_set "$tpl_di_locale"   "$LOCALE"
  433.         log "Set $tpl_di_locale = '$LOCALE'"
  434.         db_set "$tpl_di_fallbacklocale"   "$FALLBACKLOCALE"
  435.         log "Set $tpl_di_fallbacklocale = '$FALLBACKLOCALE'"
  436.  
  437.         if [ -n "$DEFAULT_COUNTRY" ]; then
  438.             log "Default country = '$DEFAULT_COUNTRY'"
  439.         fi
  440.  
  441.         db_set "$tpl_di_consoledisplay"  "$CONSOLE"
  442.         log "Set $tpl_di_consoledisplay = '$CONSOLE'"
  443.  
  444.         X_INSTALLATION_MEDIUM="$(lsb_extract X_INSTALLATION_MEDIUM)"
  445.         if [ "$sel_language" ] && [ $LANGUAGE != en ] && \
  446.            [ "$X_INSTALLATION_MEDIUM" = "floppy" ]; then
  447.             db_input high localechooser/translation/none-yet || true
  448.         fi
  449.         ;;
  450.  
  451.        12)    # Warn if translation is incomplete
  452.         set_debconf_language "$LANGUAGELIST"
  453.  
  454.         # Display warning for incomplete translations; skip it for
  455.         # automated installs to prevent a loop if the default is false
  456.         twarning=""
  457.         if [ "$sel_language" ] && \
  458.            db_get debconf/priority && [ "$RET" != critical ] && \
  459.            tstatus=$(translation-check "$LANGUAGE"); then
  460.             twarning=$(warning_template $tstatus)
  461.             db_input high $twarning || [ $? -eq 30 ]
  462.         fi
  463.         ;;
  464.  
  465.        13)    # Continue or choose alternative language
  466.         if [ "$twarning" ]; then
  467.             if db_get $twarning && [ "$RET" = false ]; then
  468.                 db_reset $twarning
  469.                 STATE=10
  470.                 continue
  471.             fi
  472.         fi
  473.  
  474.         install_lang_specific
  475.  
  476.         STATE=19
  477.         continue
  478.         ;;
  479.  
  480.        19)    # Prepare for country selection
  481.         # Keep track of values we have after language selection step
  482.         LOCALE_LANGUAGECHOOSER=$LOCALE
  483.  
  484.         FIRST_LANG="${LANGUAGELIST%%:*}"
  485.  
  486.         # We use /etc/shortlists to check if we should present a shortlist
  487.         # As we may unregister the question for shortlists, the value for the
  488.         # shortlist template is also saved with the language specific question
  489.         use_lang=""
  490.         if [ "$LOCALE" != "C" ]; then
  491.             if grep -q "^$FIRST_LANG" $SHORTLISTS; then
  492.                 use_lang=$FIRST_LANG
  493.             elif grep -q "^$LANGUAGE" $SHORTLISTS; then
  494.                 use_lang=$LANGUAGE
  495.             fi
  496.         fi
  497.  
  498.         # At this point we should have either xx, or xx_YY in LOCALE
  499.         allprio=critical
  500.         shortprio=critical
  501.         ;;
  502.  
  503.        20)    # Display a country shortlist if there is one
  504.         askedshort=
  505.         db_get $tpl_di_country
  506.         current_country="$RET"
  507.  
  508.         # Prompt with the short list for languages that are listed
  509.         # in /etc/shortlists; for others prompt with all continents
  510.         # and countries.
  511.         if [ "$use_lang" ]; then
  512.             shortlist_template="$tpl_shortlist/$use_lang"
  513.             db_unregister $tpl_shortlist || true
  514.             db_register $shortlist_template $tpl_shortlist
  515.             db_fget $tpl_di_country seen
  516.             db_fset $tpl_shortlist seen $RET || true
  517.  
  518.             # Set default value
  519.             if [ $LASTSTATE -ne 21 ]; then
  520.                 current_short=""
  521.                 if [ "$current_country" ]; then
  522.                     if has_choice $tpl_shortlist "$current_country"; then
  523.                         current_short="$current_country"
  524.                     else
  525.                         current_short=other
  526.                     fi
  527.                 elif has_choice $tpl_shortlist "$DEFAULT_COUNTRY"; then
  528.                     current_short="$DEFAULT_COUNTRY"
  529.                 fi
  530.                 db_set $tpl_shortlist "$current_short"
  531.             fi
  532.  
  533.             # If the current (preseeded) value is not in the
  534.             # shortlist, ask for continent/country instead
  535.             if [ -z "$country_preseeded" ] || \
  536.                [ "$current_short" != other ]; then
  537.                 db_input $shortprio $tpl_shortlist || [ $? -eq 30 ]
  538.                 askedshort=1
  539.             fi
  540.             country_preseeded=""
  541.         else
  542.             # If the fallback locale does not include a country
  543.             # (is not complete), we want to ask for a country at
  544.             # critical priority; example: Esperanto.
  545.             # Otherwise the default country should be good, so
  546.             # ask only at medium priority unless the current
  547.             # country is different from the default.
  548.             if is_complete_locale $FALLBACKLOCALE && \
  549.                ([ -z "$current_country" ] || \
  550.                 [ "$current_country" = "$DEFAULT_COUNTRY" ]); then
  551.                 allprio=medium
  552.             fi
  553.  
  554.             # Display continents after backing up from locale
  555.             # selection for countries without shortlist
  556.             if [ $LASTSTATE -gt 21 ]; then
  557.                 STATE=21
  558.                 continue
  559.             fi
  560.         fi
  561.         ;;
  562.  
  563.        21)    # Check if a country was selected from the short list
  564.         # and if not, allow to select a continent
  565.         if [ "$askedshort" ]; then
  566.             db_get $tpl_shortlist
  567.             COUNTRYCODE="$RET"
  568.             if [ "$COUNTRYCODE" != "other" ]; then
  569.                 STATE=24
  570.                 continue
  571.             fi
  572.         fi
  573.  
  574.         # Set default value
  575.         if [ $LASTSTATE -ne 22 ]; then
  576.             if [ "$current_country" ]; then
  577.                 set_default_continent "$current_country"
  578.             else
  579.                 set_default_continent "$DEFAULT_COUNTRY"
  580.             fi
  581.         else
  582.             # Backed up; reset continent template if no country
  583.             # was actually selected so it can get a new default
  584.             if [ -z "$current_country" ]; then
  585.                 db_reset $country_template
  586.             fi
  587.         fi
  588.         db_input $allprio $tpl_continentlist || [ $? -eq 30 ]
  589.         ;;
  590.  
  591.        22)    # Select a country on the continent
  592.         db_get $tpl_continentlist
  593.         country_template="$tpl_countrylist/$(echo $RET | sed "s/ /_/g")"
  594.         db_fget $tpl_di_country seen
  595.         db_fset $country_template seen $RET || true
  596.  
  597.         if [ "$current_country" ] && \
  598.            has_choice $country_template "$current_country"; then
  599.             db_set $country_template "$current_country"
  600.         elif db_get $country_template && [ -z "$RET" ] && \
  601.            has_choice $country_template "$DEFAULT_COUNTRY"; then
  602.             db_set $country_template "$DEFAULT_COUNTRY"
  603.         fi
  604.  
  605.         db_input $allprio $country_template || [ $? -eq 30 ]
  606.         ;;
  607.  
  608.        23)    # Get the selected country
  609.         db_get $country_template
  610.         COUNTRYCODE="$RET"
  611.         ;;
  612.  
  613.        24)    # We have a country
  614.         db_set "$tpl_di_country"  "$COUNTRYCODE"
  615.         log "Set $tpl_di_country = '$COUNTRYCODE'"
  616.  
  617.         STATE=29
  618.         continue
  619.         ;;
  620.  
  621.        29)    # Prepare for locale selection; determine default locale
  622.         # Should perhaps not be done if locale is preseeded?
  623.         if [ "$LOCALE" != "C" ]; then
  624.             LOCALE="$(get_default_locale)"
  625.  
  626.             # Fall back to a supported locale
  627.             if [ -z "$LOCALE" ]; then
  628.                 if grep -q "^$FALLBACKLOCALE " $SUPPORTEDLOCALES; then
  629.                     LOCALE="$FALLBACKLOCALE"
  630.                 else
  631.                     LOCALE=$(echo $FALLBACKLOCALE | sed -e 's/[.@].*$//')
  632.                 fi
  633.                 log "Falling back to locale '$LOCALE'"
  634.             fi
  635.         fi
  636.  
  637.         # Set the locale
  638.         db_set "$tpl_di_locale" "$LOCALE"
  639.         log "Set $tpl_di_locale = '$LOCALE'"
  640.  
  641.         # The code below adds lang_COUNTRY at the beginning of the
  642.         # language list we got from languagechooser.
  643.         # We shouldn't just add this before the former list in case
  644.         # the country is changed several times.
  645.         if [ "$COUNTRYCODE" != "$DEFAULT_COUNTRY" ] && \
  646.            [ "$COUNTRYCODE" ] && [ "$LANGUAGE" ] && \
  647.            [ "$LOCALE" != "C" ] && [ "$LANGUAGELIST" != "$LANGUAGE" ]; then
  648.             LANGUAGELIST=${LANGUAGE%%_*}_${COUNTRYCODE}:$LANGUAGELIST
  649.             db_set "$tpl_di_language" "$LANGUAGELIST"
  650.             log "Set $tpl_di_language = '$LANGUAGELIST'"
  651.         fi
  652.         ;;
  653.  
  654.        30)    # Select system locale
  655.         # We will select from supported locales for LANGUAGE_COUNTRY
  656.         if [ "$LOCALE" != "C" ]; then
  657.             POSSIBLELOCALES=$(grep -e "^${LANGUAGE%%_*}_${COUNTRYCODE}" $SUPPORTEDLOCALES | cut -d' ' -f1 || true)
  658.             if [ -z "$POSSIBLELOCALES" ]; then
  659.                 POSSIBLELOCALES=$(grep -e "^${LANGUAGE%%_*}_${DEFAULT_COUNTRY}" $SUPPORTEDLOCALES | cut -d' ' -f1 || true)
  660.             fi
  661.             if [ $(echo $POSSIBLELOCALES | wc -w) -gt 1 ]; then
  662.                 CHOICES=""
  663.                 for i in $POSSIBLELOCALES ; do
  664.                     CHOICES="${CHOICES:+$CHOICES, }$i"
  665.                 done
  666.                 db_subst $tpl_di_locale LOCALELIST "$CHOICES"
  667.                 db_input medium $tpl_di_locale || [ $? -eq 30 ]
  668.             fi
  669.         fi
  670.         ;;
  671.  
  672.        31)    # Select additional locales
  673.         db_get $tpl_di_locale
  674.         LOCALE="$RET"
  675.         log "Selected locale ($tpl_di_locale) = '$LOCALE'"
  676.  
  677.         CHOICES=
  678.         # *.UTF-8@euro locales are deprecated; don't use them
  679.         for i in $(grep -v '\.UTF-8@euro$' $SUPPORTEDLOCALES | cut -d' ' -f1 | grep -v "^$LOCALE$"); do
  680.             CHOICES="${CHOICES:+$CHOICES, }$i"
  681.         done
  682.         db_subst $tpl_supportedlocales LOCALELIST "$CHOICES"
  683.         db_fget $tpl_supportedlocales seen
  684.         if [ "$RET" = false ]; then
  685.             # Always support English (unless preseeded
  686.             # otherwise), so that we get English language packs
  687.             # etc.
  688.             if [ "$LOCALE" = C ] || [ "$LOCALE" = en_US.UTF-8 ]; then
  689.                 db_set $tpl_supportedlocales "$LOCALE"
  690.             else
  691.                 db_set $tpl_supportedlocales "$LOCALE, en_US.UTF-8"
  692.             fi
  693.         fi
  694.         db_input medium $tpl_supportedlocales || [ $? -eq 30 ]
  695.         ;;
  696.  
  697.         *)
  698.         break
  699.         ;;
  700.     esac
  701.  
  702.     LASTSTATE=$STATE
  703.     if db_go; then
  704.         STATE=$(($STATE + 1))
  705.     else
  706.         STATELEVEL=$(($STATE / 10 * 10)) # round down to multiple of 10
  707.         if [ $STATE -eq $STATELEVEL ]; then
  708.             STATE=$(($STATE - 10))
  709.         else
  710.             STATE=$(($STATE - 1))
  711.         fi
  712.     fi
  713.     db_capb backup
  714. done
  715.  
  716. if [ $STATE -eq 0 ]; then
  717.     exit 10 # back out to main menu
  718. fi
  719.  
  720. # All locales being UTF-8, unconditionnally set this, for
  721. #┬áconsole-setup purposes
  722. db_set debian-installer/charmap UTF-8
  723.  
  724. exit 0
  725.